rm(list = ls())

library(tidyverse)

## Data from 2011 census 
## Gemeinden > 10,000 inhabitants

dat <- readRDS('data/figA3.rds')

corr <- cor(dat$cit_for_non_EU_share, dat$mig_back_share, use = 'complete.obs')

p1 <- ggplot(dat, aes(x = mig_back_share, y = cit_for_non_EU_share)) + 
    geom_point(shape = 21, fill = 'white', aes(size = pop_tot)) + 
    theme_minimal() +
    stat_smooth(method = 'lm',
                col = 'black', se = F, linewidth = .4) + 
    geom_hline(yintercept = 0, linetype = 'dotted') + 
    labs(y = 'Share non-EU foreigners',
         x = 'Share migration background') +
    annotate("text", x = .594, y = .30, 
             label = paste("r = ", round(corr, 2)), 
             hjust = "right", vjust = "top",
             size = 5) + 
    scale_y_continuous(labels = scales::percent_format(accuracy = 1), limits = c(0, .35)) +
    scale_x_continuous(labels = scales::percent_format(accuracy = 1), limits = c(0, .60))+
    scale_size_continuous(range = c(.5, 10), name = 'Population\n(municipality)',
                          labels = scales::comma_format()) 

p1


